package com.xiaolin.base.array;

/**
 * @ClassName Array02
 * @Description 重复问题
 * @Detail 判断一个字符数组元素是否重复
 * @Author MyPC
 * @Date 2020/7/23
 * @Version 1.0
 */
public class Array02 {
    public static void main(String[] args) {
        char[] chars={'a','b','c'};
        System.out.println(repetition(chars));
    }
    public static boolean repetition(char[] chars){
        StringBuilder stringBuilder=new StringBuilder();
        for(int i=0;i<chars.length;i++){
            stringBuilder.append(chars[i]);
        }
        String string = stringBuilder.toString();
        boolean flag=false;
        for (int i=0;i<string.length();i++){
            //如果相同的字符不是同一个索引，代表字符有重复的
            //string.charAt(i)返回指定索引的字符string.lastIndexOf(string.charAt(i))返回指定字符的索引
            if(i != string.lastIndexOf(string.charAt(i))){
                flag=true;
                break;
            }
        }
        return flag;
    }
}
